define(["../../js/conf.js"], function(conf){
    var scope = this;
    // view scope
    scope.unMarkedList = [];
    
    // logic scope

    function isMarked(path){
        var vehicleData = window.vehicleData || {};
        return $$.any(vehicleData.fileMap, function(file){
            return file && path == file.path;
        });
    }

    function updateFileList(fileList, isImageDir){ //根据currentDir里的文件整理左侧树
        scope.unMarkedList = [];
        var markedMap = {}; //已标点位
        $$.each(fileList, function(photo){
            var basename = photo.name.replace(/.*\//, '');
            //file.path为本地文件路径，所有字符未经转义
            //file.url为file.path经过encode后的结果 
            photo.basename = basename
            if(isImageDir && $$.any(conf.pointMap, function(point, id){
                //fileMap用于本地存储
                if(photo.path == window.imageDir+'/'+point.basename){
                    // 与点位匹配
                    if(!window.vehicleData.fileMap){
                        window.vehicleData.fileMap = {};
                    }
                    if(!window.vehicleData.fileMap[id]){
                        window.vehicleData.fileMap[id] = {};
                    }
                    window.vehicleData.fileMap[id].path = photo.path;
                    markedMap[id] = photo.url;
                    return true;
                }
            })){
                return true;
            }
            if(!isMarked(photo.path)){ //是否在当前车型的fileMap里
                scope.unMarkedList.push(photo);
            }else{
                var pointid = basename.replace(/.*\//, '').replace(/\..*/, '');
                markedMap[pointid] = 1;
            }
        });
        if(isImageDir){ //如果是重新扫描imageDir，则将结果reset & save data.js
            conf.resetPoints(markedMap);
        }
    }
    
    scope.init = function(widget){
        $$.on("filenav.update", updateFileList, true);
    };
});
